package org.jeecg.common.constant.enums;

import org.jeecg.common.util.LocalDateUtil;
import org.jeecg.common.util.TupleUtil;
import org.jeecg.common.util.TwoTuple;

import java.time.LocalDate;
import java.util.Arrays;

/**
 * 标签图列表枚举
 * 类型 1=今日 2=本周 3=本月 4=本年
 *
 * @author Yafei Song
 * @author: jeecg-boot
 * @date 2022/09/28
 */
public enum LabelChartListEnum {

    /**
     * 1=今日
     */
    NOW_DAY(1, "今日", TupleUtil.twouple(LocalDate.now(), LocalDate.now())),

    /**
     * 2=本周
     */
    NOW_WEEK(2, "本周", LocalDateUtil.getLastWeekFirstDayAndLastDay(-1)),


    /**
     * 3=本月
     */
    NOW_MONTH(3, "本月", LocalDateUtil.getNowMonthFirstDayAndNowDay()),


    /**
     * 4=本年
     */
    NOW_YEAR(4, "本年", LocalDateUtil.getNowYearFirstDayAndNowDay()),

    ;


    private Integer code;


    private String desc;

    /**
     * 日期查询序列
     */
    private TwoTuple<LocalDate, LocalDate> nowDate;


    LabelChartListEnum(Integer code, String des, TwoTuple<LocalDate, LocalDate> nowDate) {
        this.code = code;
        this.desc = des;
        this.nowDate = nowDate;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public TwoTuple<LocalDate, LocalDate> getNowDate() {
        return nowDate;
    }

    public void setNowDate(TwoTuple<LocalDate, LocalDate> nowDate) {
        this.nowDate = nowDate;
    }

    /**
     * 得到查询日期
     *
     * @param type 类型
     * @return {@link TwoTuple}<{@link LocalDate}, {@link LocalDate}>
     */
    public static TwoTuple<LocalDate, LocalDate> getQueryDate(Integer type){
        return Arrays.stream(LabelChartListEnum.values()).filter(m -> type.equals(m.getCode())).findFirst().get().getNowDate();
    }
}
